package com.fzz.learning_forum.serviceImpl;

import com.fzz.learning_forum.dao.CourseMapping;
import com.fzz.learning_forum.domain.Course;
import com.fzz.learning_forum.domain.Course_People;
import com.fzz.learning_forum.service.CourseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Component
public class CourseServiceImpl implements CourseService {

    @Autowired
    private CourseMapping courseMapping;

    //创建课程
    @Override
    public Integer createCourse(Course course) {
        Date date=new Date();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        simpleDateFormat.format(date);
        course.setCreated(date);
        System.out.println(course);
        course.setStudent_num(0);
        return courseMapping.createCourse(course);
    }

    //分页查询所有课程
    @Override
    public PageInfo<Course> selectAllCourse(Integer page,Integer count) {

        PageHelper.startPage(page,count);
        List<Course> courseList = courseMapping.selectAllCourse();
        PageInfo<Course> pageInfo=new PageInfo<>(courseList);
        return pageInfo;
    }

    //分页查询自己的所有课程
    @Override
    public PageInfo<Course> selectCourseById(Integer page,Integer count,Integer id) {

        PageHelper.startPage(page,count);
        List<Course> courseList = courseMapping.selectCourseById(id);
        PageInfo<Course> pageInfo=new PageInfo<>(courseList);
        return pageInfo;
    }

    //根据id查询课程的详细信息
    @Override
    public Course selectCourseDetails(Integer id) {
        return courseMapping.selectCourseDetails(id);
    }

    //查询该课程的所有成员
    @Override
    public PageInfo<Course_People> selectAllCoursePeolpeById(Integer id, Integer page, Integer count) {

        PageHelper.startPage(page,count);
        List<Course_People> course_peopleList = courseMapping.selectCoursePeopleById(id);
        PageInfo<Course_People> pageInfo=new PageInfo<>(course_peopleList);
        return pageInfo;
    }
}
